from markdown_strings import header, table, code_block


def replacer(dictionary):
    for k, v in dictionary.items():
        if isinstance(v, dict):
            replacer(v)

        elif v is None:
            dictionary[k] = 0


def setMd(rows):
    listTable = [["数据库"],
                 ["表名"],
                 ["记录数"],
                 ["数据容量(MB)"],
                 ["数据空洞(MB)"],
                 ["索引容量(MB)"]]
    i = 0
    for row in rows:
        row: dict = rows.__getitem__(i)
        replacer(row)
        listTable[0].append(row.get("数据库"))
        listTable[1].append(row.get("表名"))
        listTable[2].append(row.get("记录数"))
        listTable[3].append(row.get("数据容量(MB)"))
        listTable[4].append(row.get("数据空洞(MB)"))
        listTable[5].append(row.get("索引容量(MB)"))
        i = i + 1
    print(listTable)

    with open("mark_down.md", 'w', encoding="utf8") as file:
        file.write(table(listTable))
